{smcl}
{* 12 July 2002}{...}
{hline}
help for {hi:labvalch}
{hline}

{title:Copy and/or delete value labels}

{p 2 11}
{cmd:labvalch} 
{it:valuelabelname} 
{cmd:,} 
[ 
{c -(} 
{cmdab:f:rom}{cmd:(}{it:numlist}{cmd:)} 
{cmdab:t:o}{cmd:(}{it:numlist}{cmd:)} 
{c |} 
{cmdab:s:wap}{cmd:(}{it:#1 #2}{cmd:)} 
{c )-}
{cmd:delete}{cmd:(}{it:numlist}{cmd:)} 
{cmdab:l:ist} 
] 


{title:Description}

{p}{cmd:labvalch} copies and/or deletes specified value labels from value label
{it:valuelabelname}.

{p}Any {cmd:label define }{it:whatever}{cmd: , modify} command that executes
changes is echoed to the monitor. 
 

{title:Remarks} 

{p}
Suppose that variable {cmd:gender} is coded 1 for male and 2 for female by 

{p 4 8}{inp:. label def gender 1 "male" 2 "female"}{p_end} 
{p 4 8}{inp:. label val gender gender} 

{p}but we find it convenient to change to 0 and 1:  

{p 4 8}{inp:. replace gender = gender - 1} 

{p}We need also to change the value labels. Slow but sure is 

{p 4 8}{inp:. label def gender 0 "male" 1 "female", modify}

{p}It would normally be best to clean up by also deleting the label
for 2:

{p 4 8}{inp:. label def gender 0 "male" 1 "female" 2 "", modify}

{p}An alternative is 

{p 4 8}{inp:. labvalch gender, f(1 2) t(0 1)} 

{p}Again, it would normally be best to clean up by also deleting the label
for 2: 

{p 4 8}{inp:. labvalch gender, f(1 2) t(0 1) delete(2)} 

{p}Suppose we have a set of labels 

{p 4 8}{inp:. label def rating 1 "poor" 2 "fair" 3 "OK" 4 "good" 5 "excellent"} 

{p}and we wish to reverse the labelling. This is done by 

{p 4 8}{inp:. labvalch rating, f(1/5) t(5/1)} 


{title:Options}

{p 0 4}{cmd:from(}{it:numlist}{cmd:)} specifies a {it:numlist} of integers
whose value labels are to be copied. These labels will not be changed unless an
element of the {it:numlist} also appears in {cmd:to( )}, or unless they are deleted
by {cmd:delete()}.  Specifying an integer for which a label does not exist is
treated as an error.
 
{p 0 4}{cmd:to(}{it:numlist}{cmd:)} specifies a {it:numlist} of integers whose
value labels are to be defined. Existing value labels are modified. 

{p}All replacements take place independently. Thus {cmd:from(2 1) to(1 2)}
would swap value labels associated with 1 and 2: the label of 2 becomes that of
1, and {it:vice versa}. ({cmd:swap(1 2)} would be another way to do this.)

{p}{cmd:from()} and {cmd:to()} must contain the same number of elements after
expansion. This syntax may not be combined with {cmd:swap()}. 

{p 0 4}{cmd:swap(}{it:#1 #2}{cmd:)} specifies two integers possessing value
labels whose labels are to be swapped. This syntax may not be combined with
{cmd:from() to()}. 

{p 0 4}{cmd:delete(}{it:numlist}{cmd:)} specifies a {it:numlist} of integers
whose value labels are to be deleted. Note that all deletions take place after
copying.  Specifying an integer for which a label does not exist is not treated
as an error, but this will be noted. 

{p 0 4}{cmd:list} invokes {cmd:label list} {it:valuelabelname} after the
changes produced. 
    
    
{title:Examples} 

{p 4 8}{inp:. labvalch rating, f(1/5) t(5/1)}

{p 4 8}{inp:. labvalch foo, f(1 1 1 1) t(2/5)}

{p 4 4}{inp:. foreach label in a b c d e {c -(}}{break}
{inp:.{space 8}labvalch `label', f(1 2) t(0 1) delete(2)}{break}
{inp:. {c )-}}


{title:Author} 

         Nicholas J. Cox, University of Durham, U.K.
         n.j.cox@durham.ac.uk


{title:Acknowledgements} 

	Fred Wolfe made interesting and helpful comments on 
	{cmd:labcopy} and {cmd:labdel}, precursors of this command.


{title:Also see}

 Manual:  {hi: [U] 15.6}, {hi:[R] label}, {hi:[R] recode} 
{p 0 19}On-line:  help for {help label}; {help numlist}; {help recode}; 
{help labedit} (if installed){p_end}

